<template>
    <div>
      <!-- 容器 -->
        <el-container>
        <el-header>
            <el-row>
              <el-col :span="8" style="text-align:left">
                <span style="font-size:25px;font-weight:bold;font-family:楷体;color:white">权限管理系统</span>     
              </el-col>
              <el-col :span="16" style="text-align:right">
                <el-avatar :size="50" :src="'http://localhost:5000' + avatar"></el-avatar>
                <span >当前的登录用户：<span style="color:red">{{fullName}}</span></span>&emsp;
                <el-button type="warning" class="el-icon-back" @click="goBack()">退出</el-button>
              </el-col>
            </el-row> 
        </el-header>
        <el-container>
            <el-aside width="200px">                              
                <el-menu default-active="2"
                         :router="true"
                         class="el-menu-vertical-demo"                  
                         @open="handleOpen" 
                         @close="handleClose"> 
                          
                    <!-- <el-submenu index="1">
                        <template slot="title"><i class="el-icon-location"></i><span slot="title">导航</span></template>
                        <el-menu-item-group title="用户">
                            <el-menu-item 
                              :index="item.menuRoute"
                              v-for="item in menuData"
                              :key="item.menuId">
                            </el-menu-item>{{item.menuName}}
                        </el-menu-item-group>                                       
                    </el-submenu> -->

                     <el-submenu index="1">
                        <template slot="title"><i class="el-icon-location"></i><span slot="title">用户管理</span></template>
                        <el-menu-item-group>
                            <el-menu-item index="/UserList">用户列表</el-menu-item>
                        </el-menu-item-group>                                       
                    </el-submenu>

                    <el-submenu index="2">
                        <template slot="title"><i class="el-icon-menu"></i><span slot="title">角色管理</span></template>
                        <el-menu-item-group>
                            <el-menu-item index="/RoleList">角色列表</el-menu-item>
                        </el-menu-item-group>    
                    </el-submenu>

                    <el-submenu index="3">
                        <template slot="title"><i class="el-icon-document"></i><span slot="title">菜单管理</span></template>
                        <el-menu-item-group>
                            <el-menu-item index="/MenuList">菜单列表</el-menu-item>                         
                        </el-menu-item-group>    
                    </el-submenu>

                    <el-submenu index="4">
                        <template slot="title"><i class="el-icon-setting"></i><span slot="title">权限管理</span></template>
                        <el-menu-item-group>
                            <el-menu-item index="">权限列表</el-menu-item>
                        </el-menu-item-group>    
                    </el-submenu>

                </el-menu>

            </el-aside>
            <el-main><router-view/></el-main>
        </el-container>
        </el-container>
    </div>
</template>
<script>
import {getMenuRoute} from "../api/menu.js";
export default {
    data() {     
      return {      
        avatar:window.JSON.parse(sessionStorage.getItem("user")).avatar,
        fullName:window.JSON.parse(sessionStorage.getItem("user")).fullName,
        menuData:[],//动态获取当前用户的角色的对应菜单权限数组
      };
    },
    methods: {
      handleOpen() {
      },
      handleClose() {      
      },
      //根据登陆的用户角色获取可访问的菜单信息  就是所谓的动态获取当前用户的角色的对应菜单权限
      getMenuData(){
          getMenuRoute().then(res=>{
              res.data.data.forEach(ele => {       
                  if(ele.menuType==1 || ele.menuType==2){
                    this.menuData.push(ele);              
                  }
              });
          })
      },
      //退出
      goBack() {
        this.$confirm('确定要退出吗?', '提示', {confirmButtonText: '确定',cancelButtonText: '取消',type: 'warning'})
        .then(() => {
          window.sessionStorage.clear(); //退出清空sessionStorage信息
          this.$router.push("/");
          this.$message({type: 'success',message: '退出成功!'});     
        }).catch(() => {
          this.$message({type: 'info',message: '已取消退出'});          
        });
      }
    },
    created() {
      //this.getMenuData();
  },
}
</script>
<style>
   .el-header{
    background-color: #6891c7;
    color: #333;
    text-align: center;
    line-height: 60px;
  }
  .el-aside {
    background-color: #f1f5fa;
    color: #333;
    text-align: center;
    line-height: 200px;
    height: calc(100vh-100px);
  }
  .el-main {
    background-color: #dadae4;
    color: #333;
    text-align: center;
    line-height: 160px;
    height: calc(100vh - 100px);
  }
  body > .el-container {
    margin-bottom: 40px;
  }
  
  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }
  
  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
  .el-header {
    background-color: #4184da;
    color: #333;
    text-align: center;
  }
  .el-menu{
     background-color: #b3c4e4;
  }
</style>